#include "ICommand.h"

ICommand::ICommand(void)
{
}

ICommand::~ICommand(void)
{
}

bool ICommand::isValidNumber(string sentence){

	bool check = true;
	if(sentence.empty()){
		check = false;
	}
	else
	{
		for(unsigned int i=0;i<sentence.size() && check;i++)
		{
			if(!isdigit(sentence[i]))
			{
				check = false;
			}
		}
	}
	return check;
}

bool ICommand::isValidDateFormat1(string dateString)
{
	int day, month, year;

	if(dateString.length() > CommonConstant::MAX_SIZE_DAY_STRING_FORMAT)
		return false;
	if (sscanf(dateString.c_str(), "%2d/%2d/%4d",&day,&month,&year)) {
        struct tm t = {CommonConstant::TM_INITIALIZATION};
        t.tm_mday = day;
        t.tm_mon = month - CommonConstant::TM_MONTH_REFERENCE;
        t.tm_year = year - CommonConstant::TM_YEAR_REFERENCE;
        t.tm_isdst = CommonConstant::TM_SUMMER_TIME_OFF;

        // normalize:
        time_t when = mktime(&t);
        struct tm norm;
		localtime_s(&norm,&when);

       if (norm.tm_mday == day    &&
           norm.tm_mon  == month - CommonConstant::TM_MONTH_REFERENCE &&
           norm.tm_year == year - CommonConstant::TM_YEAR_REFERENCE)
		   return true;
	   else
		   return false;
    }
	else
		return false;
}
